package com.mall.service.authority.controller;

import com.mall.commons.common.CommonPage;
import com.mall.commons.common.CommonResult;
import com.mall.model.domain.UmsMenu;
import com.mall.model.vo.UmsMenuVo;
import com.mall.service.authority.service.UmsMenuService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/menu")
public class UmsMenuController {
    @Autowired
    private UmsMenuService umsMenuService;
@PostMapping("/create")
public CommonResult login(@RequestBody UmsMenu umsMenu){
umsMenuService.save(umsMenu);
    return  CommonResult.success(1,"添加成功");
}
    @PostMapping("/delete/{id}")
    public CommonResult deletedById(@PathVariable Long id){
        umsMenuService.removeById(id);
        return  CommonResult.success(1,"删除成功");
    }
    @GetMapping("/list/{parentId}")
    public CommonResult<CommonPage> list(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, @PathVariable Long parentId) {
        CommonPage commonPage = umsMenuService.listByPage(pageNum, pageSize, parentId);
        return CommonResult.success(commonPage);
    }
    @GetMapping("/treeList")
    public CommonResult treeList(){
        List<UmsMenuVo> umsMenuVos = umsMenuService.treeList();

    return CommonResult.success(umsMenuVos);
    }
    /**
     * 修改后台菜单
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable Long id,
                    @RequestBody UmsMenu umsMenu){
         umsMenuService.updateOne(id,umsMenu);
         return CommonResult.success(1,"修改成功");
    }
    @PostMapping("/updateHidden/{id}")
    public CommonResult updateHidden(@PathVariable Integer id,
                          @RequestParam Integer hidden){
        return umsMenuService.updateHidden(id,hidden);
    }
    /**
     * 根据ID获取菜单详情
     */
    @GetMapping("/{id}")
    public CommonResult getById(@PathVariable Integer id){
        return umsMenuService.getById(id);
    }
}
